<?php
/**
 * 乐视换量时时统计脚本
 * User: Administrator
 * Date: 2015/4/17
 * Time: 14:03
 */

require_once('config.php');
require_once('mysqlii.php');

$postData = file_get_contents('php://input', 'r');
$postData = '36.41.175.10 - - [17/Apr/2015:14:01:17 +0800] "GET /v1/img/space.gif?mb=2030120&soi=9375&bid=com.kiloo.subwaysurfers&sver=1.38.0&ad=1&cli_ver=1.4.6.0&me=799198d03345c59738482084e9b74e58&im=2FE44C7B00FA7FB80ADEE0A06FCD7C38C2445E8C&mxh=iPhone 4s&sys=6.0.1&cli_id=3000000&osys=Windows XP-32&sys_ty=32&it_ver=&t=2021750 HTTP/1.1" 200 1093 "-" "-" -';

file_put_contents('getlog.log', $postData."\n", FILE_APPEND);

if(strpos($postData, 'bid=com.letv.iphone.client')) {
	file_put_contents('log.log', $postData."\n", FILE_APPEND);
}

$string = explode(' ', $postData);

$data['ip'] = $string[0];
//time
$unTime = trim($string[3], '['). ' '.trim($string[4], ']');

$data['cTime'] = strtotime($unTime);
//status
$data['status'] = $string[8];
//length
$data['length'] = $string[9];
//get Info
$get  = urldecode($string[6]);
$getInfo = explode('?', $get);
$getInfo = explode('&', $getInfo[1]);
foreach($getInfo as $info) {
    $infoTmp = explode('=', $info);
    $data[$infoTmp[0]] = $infoTmp[1];
}


if(isset($data['bundleid']) || isset($data['bid'])) {
    if($data['bid'] == 'com.letv.iphone.client' || $data['bundleid'] == 'com.letv.iphone.client') {
        $saveData = array();
        if(isset($data['bundleid'])) {
            $saveData['ip'] =$data['ip'];
            $saveData['ctime'] = $data['cTime'];
            $saveData['number'] = date('Ymd', $data['cTime']);
	    $saveData['type'] = 1;
	    $saveData['bundleid'] = $data['bundleid'];
        }

        if(isset($data['bid'])) {
            $saveData['ip'] =$data['ip'];
            $saveData['ctime'] = $data['cTime'];
            $saveData['number'] = date('Ymd', $data['cTime']);
	    $saveData['type'] = 2;
            $saveData['bundleid'] = $data['bid'];
        }
    } else {
        return;
    }

} else  {
    return ;
}

$db = MySqlii::getInstance();
$insertId = $db->inserts('reals_leshi', $saveData);
